<?php

class CCoreBaseUtils
{
	#<editor-fold defaultstate="collapsed" desc="construct (private)">
	private function __construct() {}
	#</editor-fold>
	
	/**
	 * @assert	('') = ''
	 * @assert	("hello world!\r\nHELLO WORLD!") = 'hello world!\r\nHELLO WORLD!'
	 * @assert	('test') = 'test'
	 */

	/**
	 * @param	string	$sText
	 * @return	string
	 */
	public static function ShowCRLF($sText)
	{
		CCore::CheckTypes(array('$sText'));
		
		return str_replace(array("\r", "\n"), array('\r', '\n'), $sText);
	}
	
	/**
	 * @param	string	$sAttributeValue
	 * @return	string
	 */
	public static function HtmlAttributeQuote($sAttributeValue)
	{
		CCore::CheckTypes(array('$sAttributeValue'));

		return str_replace('\'', '&#039;', str_replace('"', '&quot;', $sAttributeValue));
	}

	/**
	 * @param	string	$sEmail
	 * @return	string
	 */
	public static function GetAccountNameFromEmail($sEmail)
	{
		CCore::CheckTypes(array('$sEmail'));

		if (!empty($sEmail))
		{
			$iPos = strpos($sEmail, '@');
			return (false === $iPos) ? $sEmail : substr($sEmail, 0, $iPos);
		}

		return '';
	}

	/**
	 * @param	string	$sEmail
	 * @return	string
	 */
	public static function GetDomainFromEmail($sEmail)
	{
		CCore::CheckTypes(array('$sEmail'));

		if (!empty($sEmail))
		{
			$iPos = strpos($sEmail, '@');
			if (false !== $iPos)
			{
				return substr($sEmail, $iPos + 1);
			}
		}
		return '';
	}

	/**
	 * @return	string
	 */
	public static function GetTimeWithMicroSec()
	{
		$aMicroTimeItems = explode(' ', microtime());
		return date('H:i:s', $aMicroTimeItems[1]).'.'.str_pad((int) ($aMicroTimeItems[0] * 1000), 3, '0', STR_PAD_LEFT);
	}
}